﻿#ifndef ALLTOOLS_H
#define ALLTOOLS_H

#include <memory.h>
#include <QDebug>
#include <opencv2/core.hpp>
#include <opencv2/core/core.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>

#include "settingmodel.h"
#include "lah/hand_StaticLib.h"
#include "lah/emotion_StaticLib.h"
#include "lah/facecheck.h"

#include "ljh/PPMatting.h"
#include "ljh/IdCardOcr.h"
#include "ljh/FaceAction.h"
#include "DB/db.h"


class allTools
{
public:
    static std::shared_ptr<cv::VideoCapture> getCap(); //摄像头
    static PyObject* getHandPinfer();
    static cv::Mat handInfer(cv::Mat &img, int * res); //手势识别func
    static void destroyHandPinfer(); //delete
    static cv::Mat PPMatting(const std::string& device, cv::Mat &img); //精细分割func
    static const std::string OCR(cv::Mat &img); //OCR
    static int emotion(const std::string &device, const cv::Mat img); //表情识别func
    static std::shared_ptr<DB> getDB();
    static const int getEyeRotateId(cv::Mat& img); //眼球跟踪func
    static const int getFaceActionId(cv::Mat& img); //动作序列func
    static const std::string getFaceAntiSpoofingStatus(cv::Mat& img); //活体检测func
    static bool isFaceAntiSpoofingStatus(cv::Mat img); //是否为假体

    static QMap<QString, QString> getDbPeopleInfo(const QString& userId); //DB people_t
    static QMap<QString, QString> getDbUserInfo(const QString& userId); //DB user_t
    static QMap<QString, QMap<QString, QString>> getLogInfo(const QString& startTime, const QString& endTime, const QString& userId); //DB log_t
    static void updateUser_t(const QString& userId, const QString& imgPath); // insert user_t
    static void updateAction(const QString& userId, const QString& action); // update actionId
    static void insertLogInfo(const QString& time, const QString& id, const QString& result, const QString& IP); //insert new log
    static QMap<QVector<QString>,std::shared_ptr<float>> getAllFaceInfo(); // get user_t face info
    static void updateEmotion(const QString& userId, const QString& emo); //录入表情

    static cv::Mat getPoint68(cv::Mat& img); //68画点
    static std::shared_ptr<float> getFaceFeatures(cv::Mat& img); //获取人脸特征值
    static float getFaceCmp(cv::Mat& img, cv::Mat& _img); //1 vs 1 对比
    static cv::Mat getFacePic(cv::Mat img); //截取人脸
    static QMap<QString,QString> getQualityAssessorInfo(cv::Mat& img); //图片质量
    static bool isFaceOk(cv::Mat img); //图片质量是否合格
    static void drawFaceInfo(cv::Mat& img, QMap<QVector<QString>,std::shared_ptr<float>> t); //识别并且画出人脸信息

    //阈值
    static const float FACE_CMP_THRESHOLD;

private:
    allTools();
    ~allTools();
    allTools(const allTools &tools) = delete;
    const allTools& operator=(const allTools& tools) = delete;

    static std::shared_ptr<cv::VideoCapture>  camera;
    static PyObject* pInfer;
    static fastdeploy::vision::matting::PPMatting GPU_LJH;
    static fastdeploy::vision::matting::PPMatting CPU_LJH;
    static IdCardOcr ocr;
    static fastdeploy::vision::classification::PaddleClasModel GPU_LAH;
    static fastdeploy::vision::classification::PaddleClasModel CPU_LAH;
    static std::shared_ptr<DB> Face_DB;

    //seetaface6
    static std::shared_ptr<seeta::QualityOfPoseEx> QP;
    static std::shared_ptr<seeta::FaceDetector> FD;
    static std::shared_ptr<seeta::FaceLandmarker> flm68;
    static std::shared_ptr<seeta::FaceLandmarker> flm5;

    static std::shared_ptr<seeta::FaceRecognizer> FR;
    static std::shared_ptr<seeta::FaceAntiSpoofing> FAS;
    static std::shared_ptr<seeta::QualityAssessor> QAS;

    static FaceAction funcSeetaface;

};

#endif // ALLTOOLS_H
